package com.ewanghuiju.app.presenter.pintuan;

import com.ewanghuiju.app.base.RxPresenter;
import com.ewanghuiju.app.base.contract.pintuan.PintuanClassifyContract;
import com.ewanghuiju.app.model.DataManager;
import com.ewanghuiju.app.model.bean.response.PintuanClassifyResponBean;
import com.ewanghuiju.app.model.http.request.BaseRequest;
import com.ewanghuiju.app.model.http.response.Optional;
import com.ewanghuiju.app.test.bean.PintuanClassifyRightBean;
import com.ewanghuiju.app.util.RxUtil;
import com.ewanghuiju.app.widget.CommonSubscriber;

import java.util.List;

import javax.inject.Inject;

/**
 * @author sj  qq:751943509
 * @class describe
 * @time 2020/2/16
 */
public class PintuanClassifyPresenter extends RxPresenter<PintuanClassifyContract.View> implements PintuanClassifyContract.Presenter {

    private DataManager mDataManager;

    @Inject
    public PintuanClassifyPresenter(DataManager mDataManager) {
        this.mDataManager = mDataManager;
    }

    @Override
    public void getPticatesAll() {
        addSubscribe(mDataManager.getPticateslist()
                .compose(RxUtil.rxSchedulerHelper())
                .compose(RxUtil.handleMyResultCannull())
                .subscribeWith(new CommonSubscriber<Optional<List<PintuanClassifyResponBean>>>(mView) {
                    @Override
                    public void onNext(Optional<List<PintuanClassifyResponBean>> optional) {
                        if (mView != null)
                            mView.showPticatesAll(optional.getIncludeNull());
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                    }
                })
        );
    }

    @Override
    public void getPticatesToo(BaseRequest baseRequest) {

        addSubscribe(mDataManager.getPticatesToo(baseRequest)
                .compose(RxUtil.rxSchedulerHelper())
                .compose(RxUtil.handleMyResultCannull())
                .subscribeWith(new CommonSubscriber<Optional<PintuanClassifyRightBean>>(mView) {
                    @Override
                    public void onNext(Optional<PintuanClassifyRightBean> optional) {
                        if (mView != null)
                            mView.showPticatesToo(optional.getIncludeNull());
                    }

                    @Override
                    public void onError(Throwable e) {
                        super.onError(e);
                    }
                })
        );

    }

    @Override
    public void getData() {

    }
}
